package com.maple.retry.retrytask.executor;

import com.maple.retry.retrytask.RetryTaskExecutor;
import com.maple.retry.retrytask.RetryTaskResult;
import com.maple.retry.retrytask.model.RetryTaskContext;
import com.maple.retry.service.SendSmsService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author: maple
 * @version: SendSmsExecutor.java, v 0.1 2020年12月13日 19:42 maple Exp $
 */
public class SendSmsTaskExecutor implements RetryTaskExecutor {

    @Autowired
    private SendSmsService sendSmsService;

    @Override
    public RetryTaskResult execute(RetryTaskContext retryTaskContext) {

        Object context = retryTaskContext.fetchDeserializedBizContext();

        System.out.println("数据为：" + context);

        try {

            sendSmsService.send();

        } catch (Exception e) {
            return RetryTaskResult.valueOfError(e);
        }

        return RetryTaskResult.valueOfSuccess();
    }
}
